package com.santiao.publics.ui

import android.app.Activity
import android.os.Bundle
import android.view.Gravity
import android.view.View




import com.santiao.publics.base.bindings.BaseBindingDialog
import com.santiao.publics.config.Const
import com.santiao.publics.listener.OnScanConfigListener
import com.santiao.publics.util.SharedPreferencesUtil

import com.santiao.fuel.R
import com.santiao.fuel.databinding.PublicDialogBackBinding

/**
 * 关闭app弹窗
 * Author：Sid

 */
class BackDialog : BaseBindingDialog<PublicDialogBackBinding>(), View.OnClickListener {
    override fun initData() {
        initView()



    }

    override fun onResume() {
        super.onResume()
        val window = dialog!!.window
        isCancelable = false
        dialog!!.setCanceledOnTouchOutside(false)
        if (window != null) {
            window.setGravity(Gravity.CENTER)
            window.setWindowAnimations(R.style.Theme_AppCompat_Dialog_Alert)
        }
    }

    override fun initListener() {

           mBinding.flContentDialog;
        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)) {
            initAd("feed", context,mBinding.flContentDialog)

            //信息
            showAd("feed", activity)
//            //激励
//            initAd("reward", context,null)
            initAd("full", context,mBinding.flContentDialog)
//            //插屏

//
//
//                if (Const.shuangInterstitialFull) {
//                    initAd("full2", context)
//                    showAd("full2", activity)
//                }

        }
        mBinding.btnGoHome.setOnClickListener(this)
        mBinding.tvBack.setOnClickListener(this)
        mBinding.btnClose.setOnClickListener(this)




    }

    private fun initView() {


    }

    override fun onClick(v: View) {

        val id = v.id



        if (id == R.id.btn_go_home) { //直接退出
            mActivity.finish()
        } else if (id == R.id.tv_back || id== R.id.btn_close) {//再看一看
            showAd("full", activity)
            dismiss()
        }
    }

    companion object {
        private val TAG = " ==== " + BackDialog::class.java.simpleName + "  "
        private lateinit var mListener: OnScanConfigListener
        private lateinit var mActivity: Activity



        /**
         * @param loadFlag true 自动扫描 、 false 手动扫描
         * @return ScannerConfigDialog
         */
        @JvmStatic
        fun newInstance(loadFlag: Boolean, listener: OnScanConfigListener,activitys: Activity): BackDialog {
            mListener = listener
            mActivity = activitys
            val dialog = BackDialog()
            val bundle = Bundle()
            bundle.putBoolean(Const.LOAD_FLAG, loadFlag)
            dialog.arguments = bundle
            return dialog
        }
    }
}